﻿@namespace BlazorDemos.Shared

@if (!isModalType)
{
    <div class="@classNames">
        <div id="loader" class="sb-loading">
            <svg class="circular" height="40" width="40">
                <circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="6" stroke-miterlimit="10"></circle>
            </svg>
        </div>
    </div>
}
else
{
    <div class="@classNames"></div>
}

@code {
    private string classNames = "sb-body-overlay";
    private bool isModalType { get; set; }

    /// <summary>
    /// Hides the Spinner component.
    /// </summary>
    public void Hide()
    {
        classNames = SampleUtils.AddClass(classNames, SampleUtils.HIDDEN);
        StateHasChanged();
    }

    /// <summary>
    /// Shows the Spinner component.
    /// </summary>
    public void Show()
    {
        classNames = SampleUtils.RemoveClass(classNames, SampleUtils.HIDDEN);
        StateHasChanged();
    }

    /// <summary>
    /// Sets model layout to the app background to prevent mouse interaction.
    /// </summary>
    /// <param name="isModelSpinner">Disable or enable model layout based on the input.</param>
    public void ShowModalSpinner(bool isModelSpinner = true)
    {
        isModalType = isModelSpinner;
        if (isModelSpinner)
        {
            classNames = SampleUtils.AddClass(classNames, SampleUtils.MODAL_CLASS);
            classNames = SampleUtils.RemoveClass(classNames, SampleUtils.HIDDEN);
        }
        else
        {
            classNames = SampleUtils.RemoveClass(classNames, SampleUtils.MODAL_CLASS);
            classNames = SampleUtils.AddClass(classNames, SampleUtils.HIDDEN);
        }
        StateHasChanged();
    }
}

